package org.example.day03;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 第二章节2.1.5:脏读
 **/
public class MyThread7 {
    public String username = "A";
    public String password = "AA";
    synchronized public void setValue(String username,String password){
        try {
            this.username = username;
            Thread.sleep(5000);
            this.password = password;
            System.out.println("set thread name = " + Thread.currentThread().getName());
            System.out.println("username = " + username + " password = " + password);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    synchronized public void getValue(){
        System.out.println("get thread name = " + Thread.currentThread().getName());
        System.out.println("username = " + username + " password = " + password);
    }

    public static void main(String[] args) {
        try {
            MyThread7 m7 = new MyThread7();
            Thread7A ta = new Thread7A(m7);
            ta.start();
            Thread.sleep(200);
            m7.getValue();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

class Thread7A extends Thread{
    private MyThread7 m7;

    public Thread7A(MyThread7 m7) {
        this.m7 = m7;
    }

    @Override
    public void run() {
        m7.setValue("B","BB");
    }
}